import java.lang.reflect.Field;

/**
 * @author: xinmi
 * @date: 2020/11/2
 * @description:
 */
public class DemoListAllFieldsOfClass {
    public static void main(String[] args) {
        /*Field[] fields = Bean.class.getDeclaredFields();
        int nField = 1;
        System.out.println("1. List of all fields in a Bean class");
        for (Field field : fields) {
            System.out.printf("%d. %s", ++nField, field);
            System.out.printf(" %s %s",field.getType(),field.getName());
            System.out.println();
        }
        System.out.printf("%d. End - all fields of Bean class", ++nField);*/

        Bean bean = new Bean(1,"sxm","beijing");

        Field[] fields = Bean.class.getDeclaredFields();

        for (Field field : fields) {
            try {
                field.setAccessible(true);
                if(field.getName() != "id" || field.getName() != "name" )
                    System.out.println(field.getName() + ".get = " + field.get(bean));
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }

        }
    }
}
